from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from bit_api import *
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

# /browser/open 接口会返回 selenium使用的http地址，以及webdriver的path，直接使用即可
res = openBrowser("bd6b6b8e894445708eab494b9d983c93")
driverPath = res['data']['driver']
debuggerAddress = res['data']['http']

print(driverPath)
print(debuggerAddress)


# selenium 连接代码
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("debuggerAddress", debuggerAddress)

chrome_service = Service(driverPath)
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)

# driver.get('https://www.baidu.com/')
driver.get('https://www.vinted.com/')
driver.find_element(By.XPATH,'//*[@id="__next"]/div/div/div[1]/header/div/div/div[3]/div/a[1]').click()
# driver.find_element(By.XPATH,'/html/body/div[44]/div/div/div/div[2]/div/span[1]/span').click()
driver.find_element(By.CSS_SELECTOR,'[data-testid="auth-select-type--register-email"]').click()
# print(driver.page_source)
# realName_input = driver.find_element(By.CSS_SELECTOR,'[name="realName"]')
# driver.execute_script('arguments!l.value ="Derek"', realName_input)
time.sleep(1)
js = f'document.getElementById("realName").value="Derek2222"'
driver.execute_script(js)

js = f'document.getElementById("login").value="xiedaode"'
driver.execute_script(js)

js = f'document.getElementById("email").value="gudu0913@163.com"'
driver.execute_script(js)

js = f'document.getElementById("password").value="test@123"'
driver.execute_script(js)

#subscribeToNewsletter
js = f'document.getElementById("subscribeToNewsletter").checked="true"'
driver.execute_script(js)

js = f'document.getElementById("agreeRules").checked="true"'
driver.execute_script(js)

js = f'document.getElementById("agreeRules").checked="true"'
driver.execute_script(js)





print(driver.title)
